package com.leinao.media.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.leinao.media.dto.MediaThermalCameraAlarmDTO;
import com.leinao.media.entity.CameraAlarmQueryParam;
import com.leinao.media.entity.MediaThermalCameraAlarm;
import com.leinao.media.entity.Pagination;
import com.leinao.media.mapper.MediaThermalCameraAlarmMapper;
import com.leinao.media.service.MediaThermalCameraAlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 热成像相机告警Service接口实现类
 *
 * @author zhangyu
 * @date 2022/7/20 16:27
 */
@Service
public class MediaThermalCameraAlarmServiceImpl implements MediaThermalCameraAlarmService {

    @Autowired
    private MediaThermalCameraAlarmMapper alarmMapper;

    @Override
    public Pagination<MediaThermalCameraAlarmDTO> queryList(CameraAlarmQueryParam param) {
        // 分页
        Page<Object> page = PageHelper.startPage(param.getPageNum(), param.getPageSize());
        QueryWrapper<MediaThermalCameraAlarm> wrapper = new QueryWrapper<>();
        List<MediaThermalCameraAlarm> alarmList = alarmMapper.selectList(wrapper);
        // entity转dto
        List<MediaThermalCameraAlarmDTO> alarmDTOList = JSONArray.parseArray(JSON.toJSONString(alarmList), MediaThermalCameraAlarmDTO.class);
        return new Pagination<>(alarmDTOList, param.getPageNum(), param.getPageSize(), page.getTotal());
    }

}
